home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 04 - 1988 / 04.04 Apr 88 / TearOffPalette Source / Menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-02-28  |  7.2 KB  |  327 lines  |  [TEXT/KAHL]

  1. /*
  2. ----------------------------------------------------------------------------------------------------
  3. T E A R O F F   P A L E T T E
  4.  
  5.     version 1.0
  6.     by Don Melton and Mike Ritter
  7.     
  8.     Copyright (C)1987, 1988 by Impulse Technologies, Inc., all rights reserved. 
  9.     
  10.     Filename:            Menu.c
  11.     Font:                    Monaco, 9 point
  12.     Tab setting:    2
  13.     Compiler:            LightspeedC 2.15, Project type: APPL, Creator: TOPD
  14.     Segment:            Main */
  15.  
  16.  
  17.  
  18. /*
  19. ----------------------------------------------------------------------------------------------------
  20. GLOBAL CONSTANT DEFINITIONS AND VARIABLE DECLARATIONS */
  21.  
  22. #include "Constants.h"
  23. #include "Variables.h"
  24.  
  25. /*
  26. ----------------------------------------------------------------------------------------------------
  27. EXTERNAL FUNCTION DECLARATIONS */
  28.  
  29. /* None */
  30.  
  31. /*
  32. ----------------------------------------------------------------------------------------------------
  33. FORWARD FUNCTION DECLARATIONS */
  34.  
  35. pascal void DrawToolMenu();
  36. pascal short FindToolItem();
  37. pascal void HiliteToolItem();
  38. pascal void DrawPatternMenu();
  39. pascal short FindPatternItem();
  40. pascal void HilitePatternItem();
  41. pascal void DrawColorMenu();
  42. pascal short FindColorItem();
  43. pascal void HiliteColorItem();
  44. void MovePalette();
  45.  
  46.  
  47.  
  48. /*
  49. ----------------------------------------------------------------------------------------------------
  50. DRAW TOOLS */
  51.  
  52. pascal void DrawToolMenu(destRect)
  53. Rect *destRect;
  54. {
  55.     DrawPicture(GetPicture(TOOL_PICT_ID), destRect);
  56. }
  57.  
  58. /*
  59. ----------------------------------------------------------------------------------------------------
  60. DRAW PATTERNS */
  61.  
  62. pascal void DrawPatternMenu(destRect)
  63. Rect *destRect;
  64. {
  65.     short index;
  66.     Rect drawRect;
  67.     Pattern thePattern;
  68.     
  69.     if(MouseInMenu) {
  70.         EraseRect(destRect);
  71.     }
  72.     for(index = 1; index < PATTERN_COUNT; index++) {
  73.         drawRect = PatternRects[index];
  74.         drawRect.top += 1;
  75.         drawRect.left += 1;
  76.         OffsetRect(&drawRect, destRect->left, destRect->top);
  77.         
  78.         GetIndPattern(&thePattern, PATTERNS_ID, index);
  79.         FillRect(&drawRect, &thePattern);
  80.     }
  81. }
  82.  
  83. /*
  84. ----------------------------------------------------------------------------------------------------
  85. DRAW COLORS */
  86.  
  87. pascal void DrawColorMenu(destRect)
  88. Rect *destRect;
  89. {
  90.     CTabPtr colorTable;
  91.     RGBColor saveColor;
  92.     short index;
  93.     Rect drawRect;
  94.     
  95.     if(MouseInMenu) {
  96.         EraseRect(destRect);
  97.     }
  98.     HLock((*(*MaxDevice)->gdPMap)->pmTable);
  99.     colorTable = *(*(*MaxDevice)->gdPMap)->pmTable;
  100.     
  101.     GetForeColor(&saveColor);
  102.     
  103.     for(index = 1; index < COLOR_COUNT; index++) {
  104.         RGBForeColor(&colorTable->ctTable[index - 1].rgb);
  105.         drawRect = ColorRects[index];
  106.         drawRect.top += 1;
  107.         drawRect.left += 1;
  108.         OffsetRect(&drawRect, destRect->left, destRect->top);
  109.         
  110.         /* Remember that black is a pattern in Color QuickDraw. */
  111.         FillRect(&drawRect, black);
  112.     }
  113.     RGBForeColor(&saveColor);
  114.     
  115.     HUnlock((*(*MaxDevice)->gdPMap)->pmTable);
  116. }
  117.  
  118. /*
  119. ----------------------------------------------------------------------------------------------------
  120. FIND TOOL ITEM */
  121.  
  122. pascal short FindToolItem(mousePt)
  123. Point mousePt;
  124. {
  125.     short index;
  126.     
  127.     for(index = 1; index < TOOL_COUNT; index++) {
  128.         
  129.         if(PtInRect(mousePt, &ToolRects[index])) {
  130.             return(index);
  131.         }
  132.     }
  133.     return(0);
  134. }
  135.  
  136. /*
  137. ----------------------------------------------------------------------------------------------------
  138. FIND PATTERN ITEM */
  139.  
  140. pascal short FindPatternItem(mousePt)
  141. Point mousePt;
  142. {
  143.     short index;
  144.     Rect patternRect;
  145.     
  146.     for(index = 1; index < PATTERN_COUNT; index++) {
  147.     
  148.         patternRect = PatternRects[index];
  149.         patternRect.bottom += 1;
  150.         patternRect.right += 1;
  151.         
  152.         if(PtInRect(mousePt, &patternRect)) {
  153.             return(index);
  154.         }
  155.     }
  156.     return(0);
  157. }
  158.  
  159. /*
  160. ----------------------------------------------------------------------------------------------------
  161. FIND COLOR ITEM */
  162.  
  163. pascal short FindColorItem(mousePt)
  164. Point mousePt;
  165. {
  166.     short index;
  167.     Rect colorRect;
  168.     
  169.     for(index = 1; index < COLOR_COUNT; index++) {
  170.     
  171.         colorRect = ColorRects[index];
  172.         colorRect.bottom += 1;
  173.         colorRect.right += 1;
  174.         
  175.         if(PtInRect(mousePt, &colorRect)) {
  176.             return(index);
  177.         }
  178.     }
  179.     return(0);
  180. }
  181.  
  182. /*
  183. ----------------------------------------------------------------------------------------------------
  184. HILITE TOOL ITEM */
  185.  
  186. pascal void HiliteToolItem(destRect, item, hilite)
  187. Rect *destRect;
  188. short item;
  189. Boolean hilite;
  190. {
  191.     Rect hiliteRect;
  192.     
  193.     hiliteRect = ToolRects[item];
  194.     hiliteRect.bottom -= 1;
  195.     hiliteRect.right -= 1;
  196.     OffsetRect(&hiliteRect, destRect->left, destRect->top);
  197.     InvertRect(&hiliteRect);
  198. }
  199.  
  200. /*
  201. ----------------------------------------------------------------------------------------------------
  202. HILITE PATTERN ITEM */
  203.  
  204. pascal void HilitePatternItem(destRect, item, hilite)
  205. Rect *destRect;
  206. short item;
  207. Boolean hilite;
  208. {
  209.     Rect hiliteRect;
  210.     PenState savePen;
  211.     Pattern thePattern;
  212.     
  213.     hiliteRect = PatternRects[item];
  214.     hiliteRect.top += 1;
  215.     hiliteRect.left += 1;
  216.     OffsetRect(&hiliteRect, destRect->left, destRect->top);
  217.     
  218.     if(hilite) {
  219.         GetPenState(&savePen);
  220.         
  221.         PenSize(2, 2);
  222.         FrameRect(&hiliteRect);
  223.         
  224.         PenSize(1, 1);
  225.         PenMode(patBic);
  226.         InsetRect(&hiliteRect, 2, 2);
  227.         FrameRect(&hiliteRect);
  228.         
  229.         SetPenState(&savePen);
  230.     }
  231.     else {
  232.         GetIndPattern(&thePattern, PATTERNS_ID, item);
  233.         FillRect(&hiliteRect, &thePattern);
  234.     }
  235. }
  236.  
  237. /*
  238. ----------------------------------------------------------------------------------------------------
  239. HILITE COLOR ITEM */
  240.  
  241. pascal void HiliteColorItem(destRect, item, hilite)
  242. Rect *destRect;
  243. short item;
  244. Boolean hilite;
  245. {
  246.     PenState savePen;
  247.     Rect hiliteRect;
  248.     RGBColor saveColor;
  249.     CTabPtr colorTable;
  250.     
  251.     GetPenState(&savePen);
  252.     
  253.     hiliteRect = ColorRects[item];
  254.     hiliteRect.bottom += 1;
  255.     hiliteRect.right += 1;
  256.     OffsetRect(&hiliteRect, destRect->left, destRect->top);
  257.     
  258.     if(hilite) {
  259.         FrameRect(&hiliteRect);
  260.         
  261.         PenMode(patBic);
  262.         InsetRect(&hiliteRect, 1, 1);
  263.         FrameRect(&hiliteRect);
  264.         
  265.         SetPenState(&savePen);
  266.     }
  267.     else {
  268.         GetForeColor(&saveColor);
  269.         
  270.         HLock((*(*MaxDevice)->gdPMap)->pmTable);
  271.         colorTable = *(*(*MaxDevice)->gdPMap)->pmTable;
  272.         
  273.         PenMode(patBic);
  274.         FrameRect(&hiliteRect);
  275.         
  276.         SetPenState(&savePen);
  277.         RGBForeColor(&colorTable->ctTable[item - 1].rgb);
  278.         
  279.         InsetRect(&hiliteRect, 1, 1);
  280.         /* Remember that black is a pattern in Color QuickDraw. */
  281.         FillRect(&hiliteRect, black);
  282.         
  283.         HUnlock((*(*MaxDevice)->gdPMap)->pmTable);
  284.         
  285.         RGBForeColor(&saveColor);
  286.     }
  287. }
  288.  
  289. /*
  290. ----------------------------------------------------------------------------------------------------
  291. MOVE PALETTE */
  292.  
  293. void MovePalette(whichPalette, position)
  294. WindowPtr whichPalette;
  295. Point position;
  296. {
  297.     MoveWindow(whichPalette, position.h, position.v, false);
  298.     
  299.     if((TopWindow != nil) && (((WindowPeek) TopWindow)->windowKind != userKind)) {
  300.     
  301.         /* The TopWindow is a non-application document. */
  302.         if(((WindowPeek) whichPalette)->visible) {
  303.             /* The palette is visible. Bring it to the front and generate an activate event. */
  304.             SelectWindow(whichPalette);
  305.         }
  306.         else {
  307.             BringToFront(whichPalette);
  308.             /* Make the palette visible and generate an activate event. */
  309.             ShowWindow(whichPalette);
  310.         }
  311.     }
  312.     else {
  313.         /* The TopWindow is an application window or it is equal to nil. */
  314.         BringToFront(whichPalette);
  315.         
  316.         if(TopWindow == nil) {
  317.             /* Make the palette visible and generate an activate event. */
  318.             ShowWindow(whichPalette);
  319.         }
  320.         else {
  321.             /* Make the palette visible but don't generate an activate event. */
  322.             ShowHide(whichPalette, true);
  323.             HiliteWindow(whichPalette, true);
  324.         }
  325.     }
  326. }
  327.